package com.company.tcpdemo;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerThread extends Thread{


    @Override
    public void run() {
        //服务器ServerSocker
        try {
            ServerSocket serverSocket = new ServerSocket(9901);

            while(true){
                Socket socket = serverSocket.accept();

                ////////////////////接收消息//////////////////////////
                //获取输入流对象               socket的字节流->转换流->缓冲流
                BufferedReader br = new BufferedReader(
                        new InputStreamReader(socket.getInputStream(),"UTF-8"));

                //读取信息
                while(true){
                    String s = br.readLine();
                    if(s != null && !s.equals("eof")){
                        System.out.println("服务器:" + s);
                    }else{
                        break;
                    }
                }


            }

        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
